package linkedList2;

import java.util.*;

public class LinkedListDemo {
	public static void main(String[] args) {
		LinkedList dog = new LinkedList();
		Dog dog1 = new Dog("欧欧", "雪纳瑞");
		Dog dog2 = new Dog("菲菲", "拉布拉多");
		Dog dog3 = new Dog("敏敏", "泰迪");
		Dog dog4 = new Dog("旺财", "土狗");

		dog.add(dog1);
		dog.add(dog2);
		dog.add(dog3);
		dog.add(dog4);

		// 获得狗狗的总数
		System.out.println("共计有" + dog.size() + "条狗狗");
		System.out.println("分别是：");
		// 逐条打印每条狗狗
		for (int i = 0; i < dog.size(); i++) {
			Dog dogs = (Dog) dog.get(i);
			System.out.println(dogs.getName() + "\t" + dogs.getStrain());
		}

		System.out.println("\n删除之前共计有" + dog.size() + "条狗狗\n");
		// 删除狗狗
		dog.remove(0);
		dog.remove(dog3);
		// 获得删除之后狗狗的总数
		System.out.println("删除之后还有" + dog.size() + "条狗狗");
		System.out.println("分别是：");
		for (int i = 0; i < dog.size(); i++) {
			Dog dogs = (Dog) dog.get(i);
			System.out.println(dogs.getName() + "\t" + dogs.getStrain());
		}
		System.out.println();
		if (dog.contains(dog2)) {
			System.out.println("集合中包含菲菲的信息");
		} else {
			System.out.println("集合中不包含菲菲的信息");
		}

		System.out.println("***************************");

		Dog dog5 = new Dog("美美", "牧羊犬");
		Dog dog6 = new Dog("妞妞", "泰迪");

		dog.addFirst(dog5);
		dog.addLast(dog6);

		System.out.println("添加后共有狗狗条数" + dog.size());
		System.out.println("分别是：");
		for (int i = 0; i < dog.size(); i++) {
			Dog dogs = (Dog) dog.get(i);
			System.out.println(dogs.getName() + "\t" + dogs.getStrain());
		}

		Dog first = (Dog) dog.getFirst();
		System.out.println("添加后的头条狗狗是：" + first.getName());
		Dog last = (Dog) dog.getLast();
		System.out.println("添加后的末条狗狗是：" + last.getName());

		Dog first1 = (Dog) dog.removeFirst();
		System.out.println("删除的头条狗狗是：" + first1.getName());
		Dog last1 = (Dog) dog.removeLast();
		System.out.println("删除的末条狗狗是：" + last1.getName());

		System.out.println("删除后狗狗的总数是" + dog.size());
		System.out.println("分别是：");
		for (int i = 0; i < dog.size(); i++) {
			Dog dogs = (Dog) dog.get(i);
			System.out.println(dogs.getName() + "\t" + dogs.getStrain());
		}
	}
}
